package game_elements_layer.field_stuff;

import game_elements_layer.field_stuff.locations_stuff.LocationNotFoundException;
import game_elements_layer.field_stuff.locations_stuff.Locations;


/**
 * Created by vych0914 on 07.10.2014.
 */
public class FieldCreator {

    private static FieldCreator ourInstance = new FieldCreator();

    public static FieldCreator getInstance() {
        return ourInstance;
    }

    private FieldCreator() {
    }

    public Locations addNearblyLocationFor(Locations l) throws LocationNotFoundException {
        if (!Field.getInstance().getAllLocations().contains(l))
            throw new LocationNotFoundException("Exception rised while trying to create new nearbly location for "+l);
        Locations newLocation = new Locations();
        Field.getInstance().getAllLocations().add(newLocation);
        l.addNewNearbyLocation(newLocation);
        newLocation.addNewNearbyLocation(l);
        return newLocation;
    }

    public Locations addFisrtLocation(){
        if (Field.getInstance().getAllLocations().isEmpty()) {
            Locations newLocation = new Locations();
            Field.getInstance().getAllLocations().add(newLocation);
            return newLocation;
        }
        return null;
    }
}
